import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import axios from '../api/index';

class Home extends React.Component{
    constructor(){
        super()
        this.state = {
            list:[],
            mockData:[]
        }
    }
    componentWillMount(){
        axios.api.noveList().then((res)=>{
            let listArr = res.data.data
            this.setState({
                list:listArr
            })
        });

        axios.api.mockData().then((res)=>{
            let mock = res.array;
            this.setState({
                mockData:mock
            })
        })
    }
    render(){
        let listItem = this.state.list.map((item)=>{//真实接口数据
            return <li key={item.bookname.toString()}>{item.bookname}</li>
        });
        let mockItem = this.state.mockData.map((item,index)=>{//mock模拟数据
            return <li key={index.toString()}>{item.name}</li>
        });
        return(
            <div>
                <h2>接口数据源</h2>
                <ul>{listItem}</ul>
                <h2>mock数据源</h2>
                <ol>{mockItem}</ol>
            </div>
        )

    }
}
 
export default Home;
